clear all
set more off
cap log close

****************************************************************************
* This do-file extract data from the Read-only LAD files
*	- tax province
* 
* Creates the following Stata files:
*	- taxprovince_min_yyyy.dta.dta
* 	- taxprovince_8299.dta (appended files)
*   - taxprovince_0016.dta (appended files)
* 
****************************************************************************

do "H:\Lavecchia_7086\to-transfer-jan-2022\RESTAT_Replication_Programs\0_Set_Directories.do"

log using "$dir_log\1g_Extract_TaxProvince.log", replace

* Step 1: load the data from LAD read-only files

forvalues year=2004(1)2016{
use lin__i txpcoi`year' using "G:\LAD\LAD_DAL_Allcycle_v3\data\data\Stata\lad`year'.dta"
sort lin__i
gen year=`year'
foreach var in txpcoi {
rename `var'`year' `var'
}
save "$dir_data\Capital income years\taxprovince_`year'.dta", replace
}



* Step 2: append into one file (rename the variables to drop the year portion of the name)

**************** 1982 -- 1999 ****************
clear
use "$dir_data\Capital income years\taxprovince_1982.dta"
forvalues year=1983/1999{
append using "$dir_data\Capital income years\taxprovince_`year'.dta"
compress
}
*
save "$dir_data\taxprovince_8299.dta", replace


**************** 2000 -- 2016 ****************
clear
use "$dir_data\Capital income years\taxprovince_2000.dta"
forvalues year=2001/2016{
append using "$dir_data\Capital income years\taxprovince_`year'.dta"
compress
}
*
save "$dir_data\taxprovince_0016.dta", replace

use "$dir_data\taxprovince_8299.dta"
append using "$dir_data\taxprovince_0016.dta"
save "$dir_data\taxprovince.dta", replace
